﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.ViewModel;
using Bubbels.VM;

namespace Bubbels
{

    public class BallVM : NotificationObject
    {
        private int row;
        public int Row
        {
            get { return row; }
            set
            {
                row = value;
                this.RaisePropertyChanged("Row");
            }
        }

        private int columnDelta = 0;
        private int rowDelta = 0;
        private int col;

        public int ColumnWithDelta { get { return col + columnDelta; } }
        public int RowWithDelta { get { return row + rowDelta; } }
        public int Column
        {
            get { return col; }
            set
            {
                col = value;
                this.RaisePropertyChanged("Column");
            }
        }

        public void MoveHorizontal(int delta)
        {
            this.columnDelta += delta;
        }
        public void MoveVertical(int delta)
        {
            this.rowDelta += delta;
        }
        public void ClearDelta()
        {
            Row += rowDelta;
            Column += columnDelta;
            rowDelta = 0;
            columnDelta = 0;

        }

        public bool IsAliveAt(int rowIndex, int colIndex)
        {
            return this.row + rowDelta == rowIndex && col + columnDelta == colIndex && !Removed;
        }
        BallType ballType = BallType.EMPTY;
        public BallType BallType
        {
            get
            {
                return this.ballType;
            }
            set
            {
                this.ballType = value;
                this.RaisePropertyChanged("BallType");
            }
        }

        private bool selected = false;
        public bool Selected
        {
            get { return selected; }
            set
            {
                selected = value;
                this.RaisePropertyChanged("Selected");
            }
        }

        public event Action<BallVM> OnBallRemove = delegate { };
        private bool removed = false;
        public bool Removed
        {
            get { return removed; }
            set
            {
                this.removed = value;
                this.RaisePropertyChanged("Removed");
                if (true == value)
                {
                    this.OnBallRemove(this);
                }
            }

        }

    }

}
